﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using OrmAuto;;
using System.Data.Linq;
using System.Data;
using System.Data.Entity;
using System.Data.EntityClient;
using System.Data.EntityModel;
using System.Data.EntityModel.SchemaObjectModel;
using System.Threading;
using System.Web.Services;
using AjaxControlToolkit;
using System.Collections.Specialized; 

public partial class Contents_Input : System.Web.UI.Page
{
		//Querier mQuerier = null;

		protected override void OnInit(EventArgs e)
		{
				Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("It-it", true);  

				base.OnInit(e);
		}
		
    protected void Page_Load(object sender, EventArgs e)
    {
						//mQuerier = new Querier();
						
						if(!Page.IsPostBack)
								inizializza();
						
    }

				private void inizializza()
				{
						
						this.ListBoxMerceologie.DataTextField="Merceologie_Tipo";
						this.ListBoxMerceologie.DataValueField="Merceologie_ID";
						//this.ListBoxMerceologie.DataSource = mQuerier.getMerceologie(null);
						this.ListBoxMerceologie.DataBind();
						
						this.DropDownSconto.DataSource = System.Linq.Enumerable.Range(0,70)  ;
						this.DropDownSconto.DataBind();

						this.DropDownORE.DataSource = System.Linq.Enumerable.Range(0,24 );  
						this.DropDownORE.DataBind(); 
				  
				}//fM
				protected void ListBoxMerceologie_SelectedIndexChanged(object sender, EventArgs e)
				{
				    var idCatMerc = ListBoxMerceologie.SelectedValue;
				    int ID=0;
				    if(int.TryParse(idCatMerc.ToString(),out ID))
				    {
				       this.ListBoxCatMerceologie.DataTextField = "CatMerceol_Tipo" ;
				       this.ListBoxCatMerceologie.DataValueField = "CatMerceol_ID" ;
										 //this.ListBoxCatMerceologie.DataSource =  mQuerier.getCatMerceologie(null,ID);
										 this.ListBoxCatMerceologie.DataBind();
								}
								
				}//fM
				
				//bottone ok memorizza
				protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
				{
				  Page.Validate();  
						if (!Page.IsValid) return ;
						try
						{  
						  int idCatMerc =0;
								//OffertaMERCI merce = controlData(out idCatMerc);
								//if(merce == null) return ;
								
				  
								//using(var DAL = mQuerier.getDAL())
								//{ 	
								   
								//   merce.CatMerceologie = 
								//    DAL.CatMerceologie.Where(m=> m.CatMerceol_Id == idCatMerc).FirstOrDefault()  ;      

								//   DAL.AddToOffertaMERCI(merce);
								//   DAL.SaveChanges(true); 	
								//}
						}
						catch (Exception ex)
						{

								throw;
						}
						
				}

				//private OffertaMERCI controlData(out int pIdCatMerc )
				//{
				//  if(ListBoxMerceologie.SelectedIndex < 0)
				//    throw new ArgumentException("Selezionare una merceologia");
								
				//  if(this.ListBoxCatMerceologie.SelectedIndex < 0)
				//    throw new ArgumentException("Selezionare una merceologia");
						
				//  //data
				//   DateTime datasDispDAL = DateTime.MinValue  ;
				//   if(this.CheckDalSubito.Checked)
				//    datasDispDAL = DateTime.Now ;
								  
				//   if( ! string.IsNullOrEmpty(this.TxtDataDispDAL.Text.Trim()) )
				//   {							    
				//    if(! DateTime.TryParse(this.TxtDataDispDAL.Text,out datasDispDAL)  )
				//      throw new ArgumentException("Selezionare una data");
				//   }
				//   if (datasDispDAL < DateTime.Now)
				//     throw new ArgumentException("Selezionare una data valida");	
							
				//   //ore
				//   if(this.DropDownORE.SelectedIndex >= 0 )
				//    {
				//      if(datasDispDAL != null)
				//        datasDispDAL =  datasDispDAL.AddHours(double.Parse(this.DropDownORE.SelectedValue));  
				//    }		
						
				//  if(datasDispDAL == null)
				//    throw new ArgumentException("Selezionare una data");
							
						
				//  double qli =0;	
				//  if(!string.IsNullOrEmpty(TxtQTA.Text.Trim()) )
				//  {
				//    if(! double.TryParse(TxtQTA.Text,out qli))
				//      throw new ArgumentException("Qli errati");
				//  }
						

				//  if(string.IsNullOrEmpty(TxtPrice.Text.Trim()) )	
				//    throw new ArgumentException("Prezzo errato");
      
				//  decimal prezzo = 0;	
				//  if(!string.IsNullOrEmpty(TxtPrice.Text.Trim()) )
				//  {
				//    if(!decimal.TryParse(TxtPrice.Text,out prezzo))
				//      throw new ArgumentException("Prezzo errato");
				//  }		
															
				//  pIdCatMerc =int.Parse(ListBoxMerceologie.SelectedValue) ;
						 
				//  //OffertaMERCI merce = new OffertaMERCI()
				//  //{							           
				//  //  OffertaMERCI_QtàQL = qli,
				//  //  OffertaMERCI_Attiva = true, 
				//  //  OffertaMERCI_DisponibileDal = datasDispDAL,
				//  //  OffertaMERCI_IsPriceTrattabile = this.CheckIsTrattabile.Checked,
				//  //  OffertaMERCI_NoTerzisti= this.CheckNoIntermediari.Checked,
				//  //  OffertaMERCI_Prezzo = prezzo,
				//  //  OffertaMERCI_DataCreazione =DateTime.Now
				//  //};

				//  return merce;		
						
				//}//fM



				[WebMethod(true)]
				//[System.Web.Script.Services.ScriptService]
				public CascadingDropDownNameValue[] GetCatMerc(
						string knownCategoryValues,string IDcategory)
				{
						StringDictionary kv =
						CascadingDropDown.ParseKnownCategoryValuesString(
						knownCategoryValues);

						int modelId;
						if (!kv.ContainsKey("Model") ||
						!Int32.TryParse(kv["Model"], out modelId))
						{
								return null;
						}

						//Querier Q =new Querier(); 
						//var dati = Q.getCatMerceologie(null,int.Parse ( IDcategory) ); 

						List<CascadingDropDownNameValue> values =
						new List<CascadingDropDownNameValue>();

						//foreach (var item in dati )
						//{
						//  values.Add(new CascadingDropDownNameValue(
						//  item.CatMerceol_Id.ToString(),item.CatMerceol_Tipo  ));
						//}

						return values.ToArray();
				} //fM


				protected void Button1_Click(object sender, EventArgs e)
				{

				}
}//fC
